package adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bigchun.seeland.R;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import bean.ContentDataBean;
import util.GlideUtils;
import util.OrderEventMessage;


public class HorImageAdapter extends BaseAdapter {


    private ContentDataBean.DataBean textContent;
    private Context context;
    private LayoutInflater mInflater;
    List<String> mData;
    public HorImageAdapter(Context context){
        this.mInflater = LayoutInflater.from(context);
    }

    public HorImageAdapter(Context context, List<String> mData){
        this.context=context;
        this.mInflater = LayoutInflater.from(context);
        this.mData=mData;


    }
    public void setData(List<String> mData, ContentDataBean.DataBean content){
        this.mData=mData;
        this.textContent = content;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int arg0) {
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {

            holder=new ViewHolder();

            convertView = mInflater.inflate(R.layout.item_horimg, null);

            holder.img = (ImageView) convertView.findViewById(R.id.img);
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder)convertView.getTag();
        }

        /*Glide.with(context)
                .load(mData.get(position))
                .centerCrop()
//                    .placeholder(R.drawable.ic_launcher)
                .transform(new GlideCircleTransform(context,1, Color.parseColor("#ff0000")))
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(holder.img);*/


        GlideUtils.loadImagedefault2(context,mData.get(position)+"?x-oss-process=image/resize,w_220",holder.img);
        holder.img.setTag(position);
        holder.img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Log.e("点击事件","   00000");
            }
        });
        holder.img.setOnTouchListener(new View.OnTouchListener() {
            int count = 0;
            int firClick = 0;
            int secClick = 0;
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if(MotionEvent.ACTION_DOWN == motionEvent.getAction()){

                    count++;
                    Log.e("双击时间戳333333",firClick+"   "+secClick+"   "+count);
                    if(count == 1){
                        firClick = (int) System.currentTimeMillis();

                    } else if (count == 2){
                        secClick = (int) System.currentTimeMillis();
                        long as = secClick - firClick;
                        Log.e("双击时间戳",firClick+"   "+secClick+"   "+as);
                        if(secClick - firClick < 1000){
                            //双击事件
                            int i = Integer.parseInt(view.getTag() + "");
                            EventBus.getDefault().post(new OrderEventMessage("图片双击事件",i+""));
                        }
                        count = 0;
                        firClick = 0;
                        secClick = 0;
                    }
                }else if (MotionEvent.ACTION_UP == motionEvent.getAction()){
                    int timeup = (int) System.currentTimeMillis();
                    if (timeup-firClick > 1000){
                        int i = Integer.parseInt(view.getTag() + "");
                        EventBus.getDefault().post(new OrderEventMessage("图片长按事件",i+""));
                    }

                }
                return true;

            }
        });

        /*holder.img.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                saveImagUtil.showDiaLog(context,mData.get(position),textContent);
                return true;
            }
        });*/

        return convertView;
    }

    public static class ViewHolder{

        ImageView img ;



    }


}